package com.ruoyi.util;

import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.time.LocalDateTime;

public class TimeUtil {
    public static int calculateMinuteDifference(String startTime, String endTime) {
        // 在这里实现计算分钟差的逻辑
        LocalDateTime start = LocalDateTime.parse(startTime);
        LocalDateTime end = LocalDateTime.parse(endTime);

        Duration duration = Duration.between(start, end);
        long minutes = duration.toMinutes();

        return (int) minutes;
    }

    //计算停车费用
    public void  calcuCost(String startTime,String endTime){
        int minutes= TimeUtil.calculateMinuteDifference(startTime,endTime);
        double hourse=minutes/60.0;
        double day= hourse/24.0;
        //停车费用
        double cost=0;
        //每天封顶费用
        double top=30;

        //如果超过1天，先按照天数计算收费
        if(day>1){
            //计算天数费用
             cost= ((int)day)*top;
             //计算小时费用
            hourse=hourse-((int)day)*24;
            double hourseCost= TimeUtil.calcuHourseCost(hourse);
            cost+=hourseCost;
        }else{
           cost= TimeUtil.calcuHourseCost(hourse);
        }
        System.out.println("停车总费用为："+cost);
    }

    //计算小时费用
    public static double calcuHourseCost(double hourse){
        if(hourse<=1){
            return 0;
        }else if(hourse>1 && hourse<=2){
            return 10;
        }else if(hourse>2 && hourse<=4){
            return 15;
        }else if(hourse>4 && hourse<=6){
            return 20;
        }else if(hourse>6 && hourse<=12){
            return 25;
        }else{
            return 30;
        }
    }
}
